package api

import (
	__ "api-gateway/basic/activity_proto"
	"api-gateway/basic/inits"
	"api-gateway/handler/request"
	"api-gateway/handler/response"
	"github.com/gin-gonic/gin"
)

// CreateInvoice 创建发票
// @Summary 创建发票
// @Description 创建发票
// @Tags 发票
// @Accept json
// @Produce json
// @Param invoice body request.CreateInvoicere true "发票信息"
// @Success 200 {object} response.Response{data=__.CreateInvoiceResp} "创建成功"
// @Failure 400 {object} response.Response "请求参数错误"
// @Failure 500 {object} response.Response "内部服务器错误"
// @Router /invoice/create [post]
func CreateInvoice(c *gin.Context) {
	var req request.CreateInvoicere
	if err := c.ShouldBind(&req); err != nil {
		response.Error(c, 400, "请求参数错误", err.Error())
		return
	}
	invoice, err := inits.ActivityClient.CreateInvoice(c, &__.CreateInvoiceReq{
		Title:       req.Title,
		UserId:      int32(req.UserId),
		OrderId:     int64(req.OrderId),
		InvoicesNo:  req.InvoicesNo,
		BankName:    req.BankName,
		Address:     req.Address,
		InvoiceType: req.InvoiceType,
		Amount:      float32(req.Amount),
	})
	if err != nil {
		response.Error(c, 500, "内部服务器错误", err.Error())
		return
	}
	response.Success(c, "创建成功", invoice.Id)
}

// ListInvoice 查询发票
// @Summary 查询发票
// @Description 查询发票
// @Tags 发票
// @Accept json
// @Produce json
// @Param invoice body request.ListInvoicere true "发票信息"
// @Success 200 {object} response.Response{data=__.ListInvoiceResp} "查询成功"
// @Failure 400 {object} response.Response "请求参数错误"
// @Failure 500 {object} response.Response "内部服务器错误"
// @Router /invoice/list [post]
func ListInvoice(c *gin.Context) {
	var req request.ListInvoicere
	if err := c.ShouldBind(&req); err != nil {
		response.Error(c, 400, "请求参数错误", err.Error())
		return
	}
	invoice, err := inits.ActivityClient.ListInvoice(c, &__.ListInvoiceReq{
		Id: int32(req.Id),
	})
	if err != nil {
		return
	}
	response.Success(c, "查询成功", invoice)
}

// DelInvoice 删除发票
// @Summary 删除发票
// @Description 删除发票
// @Tags 发票
// @Accept json
// @Produce json
// @Param invoice body request.DelInvoicereq true "发票信息"
// @Success 200 {object} response.Response{data=__.DelInvoiceResp} "删除成功"
// @Failure 400 {object} response.Response "请求参数错误"
// @Failure 500 {object} response.Response "内部服务器错误"
// @Router /invoice/del [post]
func DelInvoice(c *gin.Context) {
	var req request.DelInvoicereq
	if err := c.ShouldBind(&req); err != nil {
		response.Error(c, 400, "请求参数错误", err.Error())
		return
	}
	_, err := inits.ActivityClient.DelInvoice(c, &__.DelInvoiceReq{
		Id: int32(req.Id),
	})
	if err != nil {
		return
	}
	response.Success(c, "删除成功", nil)
}

// AuditInvoice 审核发票
// @Summary 审核发票
// @Description 审核发票
// @Tags 发票
// @Accept json
// @Produce json
// @Param invoice body request.AuditInvoicere true "发票信息"
// @Success 200 {object} response.Response{data=__.AuditInvoiceResp} "审核成功"
// @Failure 400 {object} response.Response "请求参数错误"
// @Failure 500 {object} response.Response "内部服务器错误"
// @Router /invoice/audit [post]
func AuditInvoice(c *gin.Context) {
	var req request.AuditInvoicere
	if err := c.ShouldBind(&req); err != nil {
		response.Error(c, 400, "请求参数错误", err.Error())
		return
	}
	_, err := inits.ActivityClient.AuditInvoice(c, &__.AuditInvoiceReq{
		Id:          int32(req.Id),
		InvoicesNo:  req.InvoicesNo,
		InvoiceType: req.InvoiceType,
	})
	if err != nil {
		return
	}
	response.Success(c, "审核成功", nil)
}
